﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prop
{
    class Order
    {
        private long orderNum;
        private DateTime orderDate;
        private ShopVisitor v;
        private Double price;
        private int lineNo;
        List<OrderLine> lines;
        private List<Item> items;
        private static long lineNumber;

        DataHelper dh = new DataHelper();

        public int getVisitorId()
        {
            return v.VisitorId;
        }

       

        public Order(long orderNum, DateTime orderDate, ShopVisitor v, Double price)
        {
            this.orderDate = orderDate;
            this.orderNum = orderNum;
            this.v = v;
            this.price = price;
            items = new List<Item>();
            lines = new List<OrderLine>();

           // lineNo = 1;
        }

        public Double Price
        {
            get { return price; }
        }
        public long OrderNum
        {
            get { return orderNum; }
        }
        public DateTime OrderDate
        {
            get { return orderDate; }
        }

        public List<Item> getAllItems()
        {
            return items;
        }
        public void processOrder(int ShopNumber)// processes the order made
        {
            dh.addOrder(orderNum, price, ShopNumber, v.VisitorId);
        }
        
        public void clearOrder()// clear the order
        {
            items = new List<Item>();
        }
        public void addItem(Item it)// adds an item to the order 
        {
            items.Add(it);
        }
        public void removeItem(Item it)
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].Id == it.Id)
                {
                    items.RemoveAt(i);
                }
            }
        }
        public void addOrderLine(int prodId)
        {
            
            OrderLine ol = new OrderLine(orderNum,lineNo , prodId);
            lines.Add(ol);
            int numProds = lines.Count();

            dh.addOrderLine(orderNum,lineNo,numProds, prodId);
            lineNo++;
        }
        

    }
}
